package com.yeung.alo;

public class 组成范围内数字总和 {
    public static void main(String[] args) {
        int start = 1;
        int end = 1234;
        int[] sum = new int[end + 1];
        for (int i = start; i <= end; i++) {
            sum[i] = sum[i - 1] + getSum2(i);
        }
        System.out.println(sum[sum.length - 1]);

    }

    public static int getSum(int number) {
        if (number <= 9) return number;
        else {
            String[] numbers = String.valueOf(number).split("");
            int[] intNumbers = new int[numbers.length];
            int su = 0;
            for (int i = 0; i < numbers.length; i++) {
                su += Integer.parseInt(numbers[i]);

            }
            return su;
        }
    }

    /**
     * 方法2  利用除 和除余的思想
     *
     * @param temp
     * @return
     */
    public static int getSum2(int temp) {
        int sum = 0;
            while (temp != 0) {
                sum += (temp % 10);
                temp /= 10;
            }
        return sum;
    }
}
